//
//  MainView.swift
//  animations
//
//  Created by Ekaterina on 09.01.2023.
//

import SwiftUI

struct MainView: View {
    @State private var isSheetPresented = false;
    @State private var isAlertPresented = false;
    
    var body: some View {
        NavigationStack {
            VStack {
                List {
                    Section("Animations") {
                        NavigationLink {
                            TextAnimationView()
                        } label: {
                            Text("Text Animation")
                        }
                        NavigationLink {
                            ColorAnimationView()
                        } label: {
                            Text("Color Animation")
                        }
                        NavigationLink {
                            PathAnimationView()
                        } label: {
                            Text("Path Animation")
                        }
                        NavigationLink {
                            GeometryEffectView()
                        } label: {
                            Text("Geometry Effect")
                        }
                    }
                    
                    Section("Transitions") {
                        NavigationLink {
                            TransitionsView()
                        } label: {
                            Text("Transitions")
                        }
                    }
                    
                    Section("Navigation") {
                        NavigationLink {
                            Text("This is pushed view")
                        } label: {
                            Text("Push View")
                        }
                        
                        Text("Present View")
                            .onTapGesture {
                                isSheetPresented.toggle();
                            }
                            .sheet(isPresented: $isSheetPresented) {
                                SheetView()
                            }
                        
                        Text("Show Alert")
                            .onTapGesture {
                                isAlertPresented.toggle()
                            }
                            .alert("This is Alert", isPresented: $isAlertPresented) {
                                Button("Cancel Role", role: .cancel) {}
                                Button("Destructive Role", role: .destructive) {}
                                Button("None Role", role: .none) {}
                            } message: {
                                Text("This is alert message")
                            }
                        
                        Text("Call 123-45-67")
                            .onTapGesture {
                                let phone = "tel://123-45-67"
                                guard let url = URL(string: phone) else { return }
                                UIApplication.shared.open(url)
                            }
                        
                        Text("Open Browser")
                            .onTapGesture {
                                let web = "http://www.google.com"
                                guard let url = URL(string: web) else { return }
                                UIApplication.shared.open(url)
                            }
                    }
                    
                    Section("Others") {
                        NavigationLink {
                            LongListView()
                        } label: {
                            Text("Long List")
                        }
                        
                        NavigationLink {
                            OrientationChangeView()
                        } label: {
                            Text("Orientation View")
                        }
                    }
                }
            }
            .navigationTitle("Animations & Transitions")
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

struct MainView_Previews: PreviewProvider {
    static var previews: some View {
        MainView()
    }
}
